﻿<!DOCTYPE html>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>乐优商城--商品搜索结果页</title>
    <link rel="icon" href="assets/img/favicon.ico">
    <link href='./css/material.css' rel="stylesheet">
    <link href="./css/vuetify.min.css" rel="stylesheet">
    <script src="./js/vue/vue.js"></script>
    <script src="./js/vue/vuetify.js"></script>
    <script src="./js/axios.min.js"></script>
    <script src="./js/common.js"></script>
    <link rel="stylesheet" type="text/css" href="css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="css/pages-list.css"/>
    <link rel="stylesheet" type="text/css" href="css/widget-cartPanelView.css"/>
    <style type="text/css">
        * {
            box-sizing: unset;
        }

        .btn-arrow, .btn-arrow:visited, .btn-arrow:link, .btn-arrow:active {
            width: 46px;
            height: 23px;
            border: 1px solid #DDD;
            background: #FFF;
            line-height: 23px;
            font-family: "\5b8b\4f53";
            text-align: center;
            font-size: 16px;
            color: #AAA;
            text-decoration: none;
            out-line: none
        }

        .btn-arrow:hover {
            background-color: #1299ec;
            color: whitesmoke;
        }

        .top-pagination {
            display: block;
            padding: 3px 15px;
            font-size: 11px;
            font-weight: 700;
            line-height: 18px;
            color: #999;
            text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
            text-transform: uppercase;
            float: right;
            margin-top: 6px
        }

        .top-pagination span {
            margin-right: 10px;
        }

        /*        .logo-list li{
                    padding:8px;
                }
               .logo-list li:hover{
                    background-color: #f3f3f3;
                }*/
        .type-list a:hover {
            color: #1299ec;
        }

        .skus {
            list-style: none;
        }

        .skus li {
            list-style: none;
            display: inline-block;
            float: left;
            margin-left: 2px;
            border: 2px solid #f3f3f3;
        }

        .skus li.selected {
            border: 2px solid #dd1144;
        }

        .skus img {
            width: 25px;
            height: 25px;
        }
    </style>
    <script type="text/javascript" src="plugins/jquery/jquery.min.js"></script>
</head>

<body>0

<div id="searchApp">
    <div id="nav-bottom">
        <ly-top/>
    </div>


    <!--list-content-->
    <div class="main">
        <div class="py-container">

            <div class="bread">
                <!--面包屑-->
                <ul class="fl sui-breadcrumb">
                    <li><span>全部结果:</span></li>
                    <li><a href="#">手机</a></li>
                    <li><span>手机通讯</span></li>
                </ul>
                <!--已选择过滤项-->
                <ul class="tags-choose">
                    <li class="tag" v-for="(v,k) in search.filter" :key="k">
                        {{k==='brandId'?'品牌':k}}:<span style="color: red" v-text="findValue(k,v)">apple</span>
                        <i class="sui-icon icon-tb-close" @click="deleteFilter(k)"></i>
                    </li>
                    <!--
                    <li class="tag">
                        内存:<span style="color: red">4G</span>
                        <i class="sui-icon icon-tb-close"></i>
                    </li>
                    -->
                </ul>
                <div class="clearfix"></div>
            </div>
            <!--selector-->
            <div class="clearfix selector">
                <div class="type-wrap" v-for="(f,i) in filter" :key="i" v-if="f.k!=='brandId'" v-show="i<5||show">
                    <div class="fl key">{{f.k==='cid3'?'分类':f.k}}</div>
                    <div class="fl value">
                        <ul class="type-list">
                            <li v-for="option in f.options" v-if="f.k==='cid3'" @click="setFilter(f.k,option)" class="selected:true">
                                <a>{{option.name}}</a>
                            </li>
                            <li v-else @click="setFilter(f.k,option)">
                                <a>{{option}}</a>
                            </li>
                        </ul>
                    </div>
                    <div class="fl ext"></div>
                </div>
                <div class="type-wrap logo"  v-else >
                    <div class="fl key brand">品牌</div>
                    <div class="value logos">
                        <ul class="logo-list">
                            <li :class="{selected:option.Id===search.filter.brandId}" v-for="(option,j) in f.options" :key="j" @click="setFilter(f.k,option)">
                                <img :src="option.image" v-if="option.image"/>
                                <a v-else>{{option.name}}</a>
                            </li>
                        </ul>
                    </div>
                    <div class="fl ext">
                        <a href="javascript:void(0);" class="sui-btn">多选</a>
                    </div>
                </div>

                <div class="type-wrap" style="text-align: center">
                    <v-btn small flat @click="show=true">
                        更多
                        <v-icon>arrow_drop_down</v-icon>
                    </v-btn>
                    <v-btn small="" flat @click="show=false">
                        收起
                        <v-icon>arrow_drop_up</v-icon>
                    </v-btn>
                </div>
            </div>
            <!--details-->
            <div class="details">
                <div class="sui-navbar">
                    <div class="navbar-inner filter">
                        <ul class="sui-nav">
                            <li :class="{active:search.sortBy===''}" @click="search.sortBy=''">
                                <a href="#">综合</a>
                            </li>
                            <li>
                                <a href="#">销量</a>
                            </li>
                            <li :class="{active:search.sortBy==='createTime'}"
                                @click="search.sortBy='createTime';search.descending=true">
                                <a href="#">新品</a>
                            </li>
                            <li>
                                <a href="#">评价</a>
                            </li>
                            <li :class="{active:search.sortBy==='price'}"
                                @click="search.sortBy='price';search.descending=!search.descending">
                                <a href="#">价格
                                    <v-icon v-if="search.descending">arrow_drop_down</v-icon>
                                    <v-icon v-if="!search.descending">arrow_drop_up</v-icon>
                                </a>

                            </li>
                        </ul>
                        <div class="top-pagination">
                            <span>共 <i style="color: #222;">{{total}}</i> 件商品</span>
                            <span><i style="color: red;">{{search.page}}</i>/{{totalPage}}</span>
                            <a class="btn-arrow" href="#" style="display: inline-block" @click="lastPage">&lt;</a>
                            <a class="btn-arrow" href="#" style="display: inline-block" @click="nextPage">&gt;</a>
                        </div>
                    </div>
                </div>
                <div class="goods-list">
                    <ul class="yui3-g">
                        <li class="yui3-u-1-5" v-for="goods in goodslist" :key="goods.id">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <a :href="'item/'+goods.id+'.html'" target="_blank"><img :src="goods.selected.image" height="200"/></a>
                                    <ul class="skus">
                                        <li :class="{selected:sku.id==goods.selected.id}" v-for="sku in goods.skus"
                                            :key="sku.id" @mouseEnter="goods.selected=sku">
                                            <img :src="sku.image">
                                        </li>
                                    </ul>
                                </div>
                                <div class="clearfix"></div>
                                <div class="price">
                                    <strong>
                                        <em>¥</em>
                                        <i>{{ly.formatPrice(goods.selected.price)}}</i>
                                    </strong>
                                </div>
                                <div class="attr">
                                    <em><a :title="goods.selected.title">{{(goods.selected.title).length>20?goods.selected.title.substring(0,20)+"...":goods.selected.title}}</a></em>
                                </div>
                                <div class="cu">
                                    <em><span>促</span>
                                        <a :title="goods.subTitle">{{(goods.subTitle).length>20?goods.subTitle.substring(0,15)+"...":goods.subTitle}}</a>
                                    </em>
                                </div>
                                <div class="commit">
                                    <i class="command">已有2000人评价</i>
                                </div>
                                <div class="operate">
                                    <a href="success-cart.html" target="_blank" class="sui-btn btn-bordered btn-danger">加入购物车</a>
                                    <a href="javascript:void(0);" class="sui-btn btn-bordered">对比</a>
                                    <a href="javascript:void(0);" class="sui-btn btn-bordered">关注</a>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="fr">
                    <div class="sui-pagination pagination-large">
                        <ul>
                            <li :class="{prev:true, disabled:search.page==1}">
                                <a href="#" @click="lastPage">«上一页</a>
                            </li>
                            <li :class="{active:search.page==index(i)}" v-for="i in Math.min(5,totalPage)">
                                <a href="#" @click="search.page=index(i)">{{index(i)}}</a>
                            </li>
                            <li class="dotted" v-if="totalPage-2>search.page"><span>...</span></li>
                            <li class="{next:true, disabled:search.page==totalPage}">
                                <a href="#" @click="nextPage">下一页»</a>
                            </li>
                        </ul>
                        <div><span>共{{totalPage}}页&nbsp;</span><span>
      到第
      <input type="text" class="page-num" v-model="pageValue">
      页 <button class="page-confirm" @click="jumpPage">确定</button></span></div>
                    </div>
                </div>
            </div>
            <!--hotsale-->
            <div class="clearfix hot-sale">
                <h4 class="title">热卖商品</h4>
                <div class="hot-list">
                    <ul class="yui3-g">
                        <li class="yui3-u-1-4">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <img src="img/like_01.png"/>
                                </div>
                                <div class="attr">
                                    <em>Apple苹果iPhone 6s (A1699)</em>
                                </div>
                                <div class="price">
                                    <strong>
                                        <em>¥</em>
                                        <i>4088.00</i>
                                    </strong>
                                </div>
                                <div class="commit">
                                    <i class="command">已有700人评价</i>
                                </div>
                            </div>
                        </li>
                        <li class="yui3-u-1-4">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <img src="img/like_03.png"/>
                                </div>
                                <div class="attr">
                                    <em>金属A面，360°翻转，APP下单省300！</em>
                                </div>
                                <div class="price">
                                    <strong>
                                        <em>¥</em>
                                        <i>4088.00</i>
                                    </strong>
                                </div>
                                <div class="commit">
                                    <i class="command">已有700人评价</i>
                                </div>
                            </div>
                        </li>
                        <li class="yui3-u-1-4">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <img src="img/like_04.png"/>
                                </div>
                                <div class="attr">
                                    <em>256SSD商务大咖，完爆职场，APP下单立减200</em>
                                </div>
                                <div class="price">
                                    <strong>
                                        <em>¥</em>
                                        <i>4068.00</i>
                                    </strong>
                                </div>
                                <div class="commit">
                                    <i class="command">已有20人评价</i>
                                </div>
                            </div>
                        </li>
                        <li class="yui3-u-1-4">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <img src="img/like_02.png"/>
                                </div>
                                <div class="attr">
                                    <em>Apple苹果iPhone 6s (A1699)</em>
                                </div>
                                <div class="price">
                                    <strong>
                                        <em>¥</em>
                                        <i>4088.00</i>
                                    </strong>
                                </div>
                                <div class="commit">
                                    <i class="command">已有700人评价</i>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

</div>

<script type="text/javascript">
    var vm = new Vue({
        el: "#searchApp",
        data: {
            ly,
            search: {
                key: "", // 搜索页面的关键字
                page: 1,
                filter:{}
            },
            goodslist: [],
            totalPage: 0,
            total: 0,
            pageValue: "",
            filter:[],
            show:false
        },
        created() {
            // 判断是否有请求参数
            if (!location.search) {
                return;
            }
            // 将请求参数转为对象
            const search = ly.parse(location.search.substring(1));
            // 记录在data的search对象中
            search.page = search.page ? parseInt(search.page) : 1;
            //对排序条件进行初始化，排序主要有条件和方式
            search.sortBy = search.sortBy || "";
            search.descending = search.descending === "true" || false;
            search.filter=search.filter||{};
            this.search = search;
            // 发起请求，根据条件搜索
            this.searchFromServer();
        },
        methods: {
            searchFromServer() {
                ly.http.post("/search/page", this.search).then(({data}) => {

                    data.items.forEach(goods => {
                        var prices = goods.price
                        goods.skus = JSON.parse(goods.skus);
                        goods.selected = goods.skus[0];
                        if (this.search.sortBy === 'price' && !this.search.descending) {
                            goods.skus.forEach(sku => sku.price == Math.min(...prices) ? goods.selected = sku :"")
                        }
                        else if (this.search.sortBy === 'price' && this.search.descending) {
                            goods.skus.forEach(sku => sku.price == Math.max(...prices) ? goods.selected = sku : "")
                        }
                    })
                    this.goodslist = data.items;
                    this.total = data.total;
                    this.totalPage = data.totalPage;
                    this.filter.push(
                        {"k":"cid3",
                        "options":data.categories});
                    this.filter.push(
                        {"k":"brandId",
                            "options":data.brands});
                    data.specs.forEach(spec=>this.filter.push(spec))
                });
            },
            findValue(k,v){
              if(k!='brandId') return v;
              if (this.filter==null) return 'null';
              return this.filter.find(f=>f.k==='brandId').options[0].name;
            },
            deleteFilter(k){
                //从filter中复制属性到obj
                const {... obj} = this.search.filter;
                delete obj[k];
                //添加到search.filter中
                this.search.filter = obj;
            },
            nextPage() {
                this.search.page < this.totalPage ? this.search.page++ : this.search.page;
            },
            lastPage() {
                this.search.page > 1 ? this.search.page-- : this.search.page;
            }
            ,//计算页面上显示的页码按钮 ,每次显示五个按钮，当前页按钮应居中
            index(i) {
                if (this.search.page <= 3) {
                    //当当前页小于3时，直接从1开始遍历，每个按钮的值为i
                    return i;
                } else if ( this.search.page < this.totalPage - 2 ) {
                    //当当前页大于等于3并且小于总页数减2时，从当前页-3加上当前的第i个按钮开始显示按钮数值
                    //如当前页为10时，应从10-3+1=8开始显示
                    return this.search.page - 3 + i;
                } else {
                    //当当前页大于totalPage-2时，如：totalPage=12，应从12-5+1=8开始显示
                    return this.totalPage - 5 + i;
                }
            },
            jumpPage() {
                this.search.page = parseInt(this.pageValue);
            },setFilter(key,option){
                const obj={};
                Object.assign(obj,this.search);
                if(key=='cid3'||key=='brandId'){
                    obj.filter[key]=option.id;

                }
                else{
                    obj.filter[key]=option;
                }
                this.search=obj;
            }
        }, watch: {
            search: {
                deep: true,
                handler(val, old) {
                    if (!old || !old.key) {
                        // 如果旧的search值为空，或者search中的key为空，证明是第一次
                        return;
                    }
                    // 把search对象变成请求参数，拼接在url路径
                    window.location.href = "http://www.leyou.com/search.html?" + ly.stringify(val);
                }
            }
        },
        components: {
            lyTop: () => import("./js/pages/top.js")
        }
    });
</script>
<!-- 底部栏位 -->
<!--页面底部，由js动态加载-->
<div class="clearfix footer"></div>
<script type="text/javascript">$(".footer").load("foot.html");</script>
<!--页面底部END-->

</body>
<!--购物车单元格 模板-->
<script type="text/template" id="tbar-cart-item-template">
    <div class="tbar-cart-item">
        <div class="jtc-item-promo">
            <em class="promo-tag promo-mz">满赠<i class="arrow"></i></em>
            <div class="promo-text">已购满600元，您可领赠品</div>
        </div>
        <div class="jtc-item-goods">
            <span class="p-img"><a href="#" target="_blank"><img src="{2}" alt="{1}" height="50" width="50"/></a></span>
            <div class="p-name">
                <a href="#">{1}</a>
            </div>
            <div class="p-price"><strong>¥{3}</strong>×{4}</div>
            <a href="#none" class="p-del J-del">删除</a>
        </div>
    </div>
</script>
<!--侧栏面板结束-->
<script type="text/javascript" src="js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#service").hover(function () {
            $(".service").show();
        }, function () {
            $(".service").hide();
        });
        $("#shopcar").hover(function () {
            $("#shopcarlist").show();
        }, function () {
            $("#shopcarlist").hide();
        });

    })
</script>
<script type="text/javascript" src="js/model/cartModel.js"></script>
<script type="text/javascript" src="js/czFunction.js"></script>
<script type="text/javascript" src="js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="js/widget/cartPanelView.js"></script>


</html>